/*******************************************************************************
**
** Copyright (c) 2011 - The OWE Team
**
** This file is part of OWE.
**
** OWE is a free software; you can redistribute it and/or
** modify it under the terms of the GNU Lesser General Public
** License as published by the Free Software Foundation; version
** version 2.1 of the License.
**
** OWE is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
** Lesser General Public License for more details.
**
** You should have received a copy of the GNU Lesser General Public
** License along with OWE. If not, see <http://www.gnu.org/licenses/>.
**
*******************************************************************************/

#include <tut/tut.hpp>
#include <tut/tut_console_reporter.hpp>

#include <owe/configurationdocument.h>
#include <owe/widgetpackage.h>
#include <owe/ustring.h>

OWE_USE_NAMESPACE

namespace tut
{
    test_runner_singleton runner;

    struct ConfigurationDocument_data {
        ConfigurationDocument_data() {
            validPackage = new WidgetPackage(TEST_DATA"/widget01/");
            invalidPackage = new WidgetPackage("any_invalid_widget/");
        }

        ~ConfigurationDocument_data() {
            delete validPackage;
            delete invalidPackage;
        }

        WidgetPackage *validPackage;
        WidgetPackage *invalidPackage;
    };


    typedef test_group<ConfigurationDocument_data> testgroup;
    testgroup shared_ptr_group("ConfigurationDocument");
    typedef testgroup::object testobject;

    template<>
    template<>
    void testobject::test<1>() {
        set_test_name("ConfigurationDocument::isValid() const");

        ConfigurationDocument doc1(*validPackage);
        ensure(doc1.isValid() == true);

        ConfigurationDocument doc2(*invalidPackage);
        ensure(doc2.isValid() == false);
    }

    template<>
    template<>
    void testobject::test<2>() {
        set_test_name("ConfigurationDocument::widgetElement() const");

        ConfigurationDocument doc1(*validPackage);
        ensure(doc1.widgetElement() != 0);

        ConfigurationDocument doc2(*invalidPackage);
        ensure(doc2.widgetElement() == 0);
    }
}

int main(void)
{
    tut::console_reporter reporter;
    tut::runner.get().set_callback(&reporter);
    tut::runner.get().run_tests();

    return reporter.all_ok() ? 0 : 1;
}
